package org.endy.leisure.diaTracker.controller

import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.tags.Tag
import kotlinx.coroutines.reactor.mono
import org.endy.leisure.diaTracker.entity.User
import org.endy.leisure.diaTracker.entity.exam.Exam
import org.endy.leisure.diaTracker.service.ExamService
import org.endy.leisure.diaTracker.service.UserService
import org.endy.leisure.diaTracker.util.CommUtils
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono

@RestController
@RequestMapping("/index")
@Tag(name = "index服务", description = "index测试服务")
class IndexController(private val userService: UserService, private val examService: ExamService) {

    @Operation(summary = "index请求", description = "echo请求测试")
    @GetMapping("/")
    fun index(request: IndexRequest): Mono<WebResponse<IndexResponse>> = mono {
        WebResponse(data = IndexResponse(request.name))
    }

    @Operation(summary = "系统数据初始化", description = "用户初始化系统数据")
    @GetMapping("/initData")
    fun init(): Mono<WebResponse<IndexResponse>> = mono {
        // 初始化admin角色用户
        userService.createUser(
            User(
                phone = "18273662418",
                roleType = "admin",
                password = CommUtils.md5Sign("12345665")
            )
        )
        // 初始化试卷信息
        examService.createExam(
            Exam(
                title = "ICU医护人员血糖管理知识调查问卷",
                paperPath = "",
                answer = "B,B,C,C,C,C,C,D,B,C,B,C,B,D,D,C,D,C,B,B,B,B,B,C,C",
                paperType = 1
            )
        )
        WebResponse()
    }

}